<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
        <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title></title>
		<script type="text/javascript" src="../script/config.js"></script>
		<style>
			body{
				background-color:rgb(238,238,238);
			}
			.body_a{
				padding:1rem;
				background-color:white;
				margin-bottom:1rem;
				height:60px;
			}
      .body_ab{
      	float:left;
				width:20%;
				background-color: #f16c3c;
				height:40px;
				text-align:center;
				line-height:40px;
				color:white;
				margin-left:2.5%;
				margin-right:2.5%;
				margin-top:10px;
				margin-bottom:10px;
				border-radius:5px;
      }
			.body_ac{
				float:left;
				width:50%;
				background-color: white;
				height:40px;
				text-align:center;
				line-height:40px;
				margin-top:10px;
				margin-bottom:10px;
				border-radius:5px;
			}
			.body_ad{
				float:left;
				width:20%;
				background-color: gray;
				height:40px;
				text-align:center;
				line-height:40px;
				color: white;
				margin-left:2.5%;
				margin-right:2.5%;
				margin-top:10px;
				margin-bottom:10px;
				border-radius:5px;
			}
			.foot_a{
				position:relative;
				margin-left:10%;
				margin-right:10%;
				margin-bottom: 10px;
				width:80%;
				height:45px;
				bottom:0;
				left:0;
				font-size:14px;
				text-align: center;
				line-height:45px;
				background-color: #f16c3c;
				font-size: 20px;
				color:white;
				border-radius:8px;
			}
			.bod{
				width:100%;
				overflow:auto;
			}
			.foot_sure{
				margin-top:10px;
				background-color:white;
				padding:30px;
			}
			.sure_upl{
				margin:0 auto;
				width:50%;
				height:35px;
				border-radius:10px;
				background-color:#f16c3c;
				text-align:center;
				line-height:35px;
				color:white;
			}
		</style>
	</head>
	<body>
		   <div id="bod" class="bod">
		   </div>
       <!-- <div class="body_a"><div class="body_ac"><label><input type="radio" name="plate_number"/><span>车牌号:苏FLL901</span></label></div><div class="body_ab">查看</div><div class="body_ad">删除</div></div>
       <div class="body_a"><div class="body_ac"><label><input type="radio" name="plate_number"/><span>车牌号:1111111</span></label></div><div class="body_ab">查看</div><div class="body_ad">删除</div></div> -->
       <div class="foot_a" id="foot_a">添加</div>
	</body>
  <script type="text/javascript" src="../script/jquery-3.2.1.min.js"></script>
  <script type="text/javascript" src="../script/swipe.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
      <script type="text/javascript">
      apiready = function(){

				  var user = $api.getStorage('user');
					var lorryid=user.lorryid;
					var phone=user.telephone;
					var password=user.pass;
					var time=user.time;
					if(user.flag==1){
            $api.html($api.dom('body'),'<div>您是派送员</div><div class="foot_sure" id="foot_up"><div class="sure_upl">升级运输车司机</div></div>')
					}else{
						$api.get(url+'app.php/getAppLorry?phone='+phone,function(ret){
							for(var i=0;i<ret.app_lorrys.length;i++){
                $api.append($api.dom('#bod'), '<div class="body_a"><div class="body_ac"><label><input type="radio" name="plate_number" id="c'+ret.app_lorrys[i].app_lorry_id+'"/><span>车牌号'+ret.app_lorrys[i].plate_number+'</span></label></div><div class="body_ab" id="d'+ret.app_lorrys[i].app_lorry_id+'">查看</div><div class="body_ad" id="e'+ret.app_lorrys[i].app_lorry_id+'">删除</div></div>');
								var flag=ret.app_lorrys[i].flag;
								$api.addEvt($api.dom('#c'+ret.app_lorrys[i].app_lorry_id),'click',function(){
										var user = $api.getStorage('user');
										var lorryid=user.lorryid;

                  var id=$api.attr(this,'id').substring(1);
									$api.post(url+'app.php/changeTime',{
											body: {lorry_id:id}
									 },function(ret1){
												 $api.rmStorage('user')
			 									var key = 'user';
			 									var user = {};
			 									user.time=ret1.time;
			 									user.lorryid=id;
			 									user.telephone=phone;
			 									user.flag=flag;
			 									user.pass= password;
			 									$api.setStorage(key, user);
												api.toast({
													 msg:ret1.plate_number+'为当前车辆',
													 duration: 2000,
													location: 'middle'
												});
											});
								});
								$api.addEvt($api.dom('#d'+ret.app_lorrys[i].app_lorry_id),'click',function(){
                    var id=$api.attr(this,'id').substring(1);

										api.openWin({
											name: 'appLorry_main',
											url:  'appLorry_main.html',
											pageParam: {
		                    name:id
                      }
										});
								});
								$api.addEvt($api.dom('#e'+ret.app_lorrys[i].app_lorry_id),'click',function(){
                    var id=$api.attr(this,'id').substring(1);
										if(!$api.attr($api.dom('#c'+id),'checked')){
											api.confirm({
						 						 title: '删除',
						 						 msg: '是否删除',
						 						 buttons: ['确定', '取消']
						 				 }, function(ret, err) {
						 						 var index1 = ret.buttonIndex;
												 if(index1==1){
													 $api.post(url+'app.php/changeIsExist',{
				                       body: {lorry_id:id}
				 										},function(ret1){
	                              if(ret1.result==0){
																	api.toast({
																		 msg: ret1.desc,
																		 duration: 2000,
																		location: 'middle'
																	});
																	$api.setStorage('yingxiang', 1);
																	setTimeout("api.closeWin({name:'main'})",550);
																	api.openWin({
																		name: 'index',
																		url:  '../index.html',
																		reload:true,
																	});
																}else{
																	api.toast({
																		 msg: ret1.desc,
																		 duration: 2000,
																		location: 'middle'
																	});
																}
				 										},'json');
												 }
											 });
										}else{
											api.toast({
												 msg:'请选择其他车辆为当前车辆',
												 duration: 2000,
												location: 'middle'
											});
										}

								});
                   $api.attr($api.dom('#c'+lorryid),'checked','checked');
							}


						},'json');
					}
  $api.addEvt($api.dom('#foot_a'),'click',function(){
		var user = $api.getStorage('user');
		var lorryid=user.lorryid;
		api.openWin({
			name: 'addLorryA',
			url:'addLorryA.html',
			pageParam: {
				lorryid:lorryid
			}
		});
	});


	$api.addEvt($api.dom('#foot_up'), 'click',function(){
		api.openWin({
			name: 'upgrade1',
			url:  '../upgrade1.html',
			pageParam: {
			lorryid: lorryid,
		 }
		});
	});
}

var check=function(id,time){
  $api.post(url+'app.php/check',{
        body:{lorryid:id,
              time:time,}
       },function(ret){
        if(ret.result==4){
          // alert(ret.desc);
          api.openWin({
            name: 'index',
            url:  '../index.html',
          });
           setTimeout("api.closeWin({name:'main'})",650);
           $api.rmStorage('password');
           var key = 'user';
           var user = {};
           var aa=$api.getStorage(key);
           user.lorryid=aa.lorryid;
            user.telephone=aa.telephone;
           user.flag= aa.flag
           user.pass= '';
           $api.setStorage(key, user);
           api.alert({
             title: '提示消息',
             msg: ret.desc,
             buttons: ['确定']
           });
         }else{
          //  alert(ret.desc);
         }
       });
}
      </script>
</html>
